[Vulkan] Initialize wgpu objects from raw handles, part 2 #1850
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
#1609
Description
While #1609 was needed to support OpenXR applications, this PR aims to support OpenXR runtime/SteamVR drivers implementations.
Instance::from_raw()
,Adapter::device_from_raw()
andDevice::texture_from_raw()
are made more flexible to accomodate both use-cases.Recap:
(With ownership I mean the responsibility of destroying the object)
In a OpenXR game, the instance and device are created by the runtime and owned by the application. The session is created by the runtime using the instance and device and owned by the application. The swapchain textures are created by the runtime and owned by the runtime. Wgpu textures used to access the swapchain are created by the application and the handles are owned by the runtime.
The wgpu textures must go out of scope before destroying the swapchain and session, which must be destroyed before destroying the device and instance. Drop guards are used as barriers to prevent the drop of objects on which
Instance
andTexture
depends on, by keeping a reference to it. The presence or absence of drop guards is used also as flag for deciding if to destroy the underlying Vulkan object (drop_guard == Some
forInstance::from_raw()
,drop_guard == None
forDevice::texture_from_raw()
).This table summarizes the argument values that should be used for each call:
Instance::from_raw()
drop_guard == Some
drop_guard == None
Adapter::device_from_raw()
handle_is_owned == true
handle_is_owned == false
Device::texture_from_raw()
drop_guard == Some
drop_guard == None
The OpenXR runtime does not need drop guards since it's the client application that is resposible for managing the lifetime and drop order of the objects. The device does not use the
drop_guard
because not needed to enforce drop safety in the context of OpenXR.Testing
None for now. I need ash-rs/ash#457 to be merged (and then wgpu to be updated with the new ash verison), which is orthogonal to this PR.